#!/usr/bin/env node
const shell = require('shelljs')
const open = require('open')

const args = process.argv.slice(2)

const PORT = args[0] === '-p' ? args[1] : '3000'

shell.echo('正在关闭运行的 Docker 容器')
const STOP_SHELL = `docker stop game_videos_manager`
shell.exec(STOP_SHELL, { async: false, silent: true })

shell.echo('正在删除 Docker 容器')
const DELETE_SHELL = `docker rm game_videos_manager`
shell.exec(DELETE_SHELL, { async: false, silent: true })

shell.echo('启动 Docker 容器中...')
const SHELL = `docker run --name game_videos_manager -p ${PORT}:3000 game_videos_manager:latest`
shell.exec(SHELL, { async: true })

open('http://localhost:' + PORT)
